<div class="pageContent">
	<form action="">
		<div class="mini-toolbar">
			<input type="text" id="workcenterSearch" /> <a class="buttonActive" href="javascript:void(0)" id="searchTree"> <span><@label
					key='search.B'>搜索</@label></span>
			</a>
		</div>
		<div style="border: 1px solid #D8DFE5; border-top: none;">
			<div id="menuBar" class="pBar pBarBorder">
				<ul class="toolBar">
					<li><a class="collapse" id="collapsable" title='<@label key="collapseAll.D">全部收起</@label>'> <span><@label
								key="collapse.B">收起</@label></span>
					</a></li>
					<li><a class="expand" id="expandable" title='<@label key="expandAll.D">全部展开</@label>'> <span><@label key="expand.B">展开</@label></span>
					</a></li>
				</ul>
			</div>
			<div id="workcenterTree" layoutH="100"><#include "andon/tree.html"></div>
		</div>
		<!-- 操作类型（移动/复制） -->
		<input type="hidden" name="operationType" value="${operationType}" />
		<!-- 选择的ANDON数据json -->
		<input type="hidden" name="andons" value="${andons}" />
		<!-- 源作业单元 -->
		<input type="hidden" name="sWorkUnitCode" value="${sWorkUnitCode}" />
		<!-- 源ANDON组 -->
		<input type="hidden" name="sAndonGroup" value="${sAndonGroup}" />
		<!-- 目的作业单元 -->
		<input type="hidden" id="tWorkUnitCode" name="tWorkUnitCode" />
		<!-- 目的ANDON组 -->
		<input type="hidden" id="tAndonGroup" name="tAndonGroup" />
		<div class="formBar">
			<ul>
				<li>
					<div class="buttonActive">
						<div class="buttonContent">
							<button id="save" type="button" name="btnSave"><@label key="save.B">保存</@label></button>
						</div>
					</div>
				</li>
				<li>
					<div class="buttonActiveGrey" style="margin-left: 10px;">
						<div class="buttonContent">
							<button type="button" class="close"><@label key="cancel.B">取消</@label></button>
						</div>
					</div>
				</li>
			</ul>
		</div>
	</form>
</div>
<script>
	(function($) {
		var $page = DWZ.context();

		$page.find("#searchTree").baseTreeSearch({
			inputTextId: "#workcenterSearch",
			alertMsg: "<@label key='Tree_search_Input.D'>输入名称进行查询</@label>", //提示内容，要考虑国际化，传自后台
			$p: $page
		});

		$page.find("#collapsable")._treeCollapsable({
			$p: $page
		})

		$page.find("#expandable")._treeExpandable({
			$p: $page
		});

		var $tWorkUnitCode = $page.find('#tWorkUnitCode'), $tAndonGroup = $page.find('#tAndonGroup');

		$page.find('.tree').on('check', '.andonGroup, .workUnit, .workCenter', function() {
			var $this = $(this);
			if ($this.is('.workCenter')) {
				$tWorkUnitCode.val('');
				$tAndonGroup.val('');
			} else if ($this.is('.workUnit')) {
				$tWorkUnitCode.val($this.attr('workunitCode'));
				$tAndonGroup.val('');
			} else if ($this.is('.andonGroup')) {
				$tWorkUnitCode.val($this.attr('workunitCode'));
				$tAndonGroup.val($this.attr('andonGroup'));
			}
			return false;
		});

		$page.find('#save').click(function() {
			var postData = $(this).closest('form').serializeArray(), check = {};

			$.each(postData, function() {
				check[this.name] = this.value;
			});
			console.log(check);

			if (!check.tWorkUnitCode) {
				alertMsg.error('请选择目的作业单元或ANDON组！');
				return false;
			}

			if (check.sWorkUnitCode === check.tWorkUnitCode) {
				if (check.operationType === 'move') {
					if (!check.sAndonGroup || (check.sAndonGroup && check.tAndonGroup && check.sAndonGroup === check.tAndonGroup)) {
						alertMsg.error('同一作业单元下，只能移出组或者移动到其他组！');
						return false;
					}
				} else {
					alertMsg.error('同一作业单元下数据已存在，不能复制！');
					return false;
				}
			}

			DWZ.ajax({
				url: hostUrl + '/andon/batchSave',
				data: postData,
				success: function(json) {
					$.pdialog.closeCurrent();
					$page.data('_parent').find('#jGridForAndonList').jGrid('loadData');
					if (json.data) {
						if (!DWZ.showDetailedReports(json) && json[DWZ.keys.message] && alertMsg) {
							alertMsg.correct(json[DWZ.keys.message]);
						}
					} else if (json[DWZ.keys.message] && alertMsg) {
						alertMsg.correct(json[DWZ.keys.message]);
					}
				}
			});
			return false;
		});

	})(jQuery);
</script>
